package com.zhc.dejingapi.config;

import com.zhc.dejingapi.job.*;
import org.quartz.JobDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

import java.util.Date;

@Configuration
public class QuartzConfig {
    //https://blog.csdn.net/qq_44209274/article/details/112319939
    //多个Job

    //任务1 QingflowInfoSynJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingflowInfoSynJobDetail")
    public MethodInvokingJobDetailFactoryBean QingflowInfoSynJobDetail(QingflowInfoSynJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器1
    @Bean(name = "QingflowInfoSynTrigger")
    public SimpleTriggerFactoryBean QingflowInfoSynTrigger(JobDetail QingflowInfoSynJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingflowInfoSynJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(300000);
        return trigger;
    }



    //任务2 QingflowInfoSynJob
    /**
     * 配置定时任务2 的任务实例
     * @param  job 任务
     */
    @Bean(name = "ERPProdBaseDataToQingJobDetail")
    public MethodInvokingJobDetailFactoryBean ERPProdBaseDataToQingJobDetail(ERPProdBaseDataToQingJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器2
    @Bean(name = "ERPProdClassToQingTrigger")
    public SimpleTriggerFactoryBean ERPProdClassToQingTrigger(JobDetail ERPProdBaseDataToQingJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(ERPProdBaseDataToQingJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(3000000);
        return trigger;
    }



    @Bean(name = "CheckADJobDetail")
    public MethodInvokingJobDetailFactoryBean CheckADJobDetail(CheckADJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器3
    @Bean(name = "CheckADTrigger")
    public SimpleTriggerFactoryBean CheckADTrigger(JobDetail CheckADJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(CheckADJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(10000);
        return trigger;
    }

    //任务4 QingflowDownDataJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingflowDownDataJobDetail")
    public MethodInvokingJobDetailFactoryBean QingflowMoOrderUploadJobDetail(QingflowDownDataJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器4
    @Bean(name = "QingflowDownDataTrigger")
    public SimpleTriggerFactoryBean QingflowDownDataTrigger(JobDetail QingflowDownDataJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingflowDownDataJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(60000);
        return trigger;
    }

    //任务5 QingflowInfoSynJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingflowMoOrderUploadJobDetail")
    public MethodInvokingJobDetailFactoryBean QingflowMoOrderUploadJobDetail(QingflowMoOrderUploadJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器5
    @Bean(name = "QingflowMoOrderUploadTrigger")
    public SimpleTriggerFactoryBean QingflowMoOrderUploadTrigger(JobDetail QingflowMoOrderUploadJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingflowMoOrderUploadJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(300000);
        return trigger;
    }


    //任务6 QingflowInfoSynJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingMoldBindDataDownJobDetail")
    public MethodInvokingJobDetailFactoryBean QingMoldBindDataDownJobDetail(QingMoldBindDataDownJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器6
    @Bean(name = "QingMoldBindDataDownTrigger")
    public SimpleTriggerFactoryBean QingMoldBindDataDownTrigger(JobDetail QingMoldBindDataDownJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingMoldBindDataDownJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(300000);
        return trigger;
    }


    //任务7 QingflowInfoSynJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingWorkTaskDownJobDetail")
    public MethodInvokingJobDetailFactoryBean QingWorkTaskDownJobDetail(QingWorkTaskDownJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器7
    @Bean(name = "QingWorkTaskDownTrigger")
    public SimpleTriggerFactoryBean QingWorkTaskDownTrigger(JobDetail QingWorkTaskDownJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingWorkTaskDownJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(300000);
        return trigger;
    }


    //任务8 QingDepPersonDownJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingDepPersonDownJobDetail")
    public MethodInvokingJobDetailFactoryBean QingDepPersonDownJobDetail(QingDepPersonDownJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器8
    @Bean(name = "QingDepPersonDownTrigger")
    public SimpleTriggerFactoryBean QingDepPersonDownTrigger(JobDetail QingDepPersonDownJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingDepPersonDownJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(300000);
        return trigger;
    }


    //任务9 QingDepPersonDownJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingSfcBaseInfoDownJobDetail")
    public MethodInvokingJobDetailFactoryBean QingSfcBaseInfoDownJobDetail(QingSfcBaseInfoDownJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器9
    @Bean(name = "QingSfcBaseInfoDownTrigger")
    public SimpleTriggerFactoryBean QingSfcBaseInfoDownTrigger(JobDetail QingSfcBaseInfoDownJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingSfcBaseInfoDownJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(20000);
        return trigger;
    }

    //任务10 QingWaterBoiledDataDownJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "QingWaterBoiledDataDownJobDetail")
    public MethodInvokingJobDetailFactoryBean QingWaterBoiledDataDownJobDetail(QingWaterBoiledDataDownJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器10
    @Bean(name = "QingWaterBoiledDataDownTrigger")
    public SimpleTriggerFactoryBean QingWaterBoiledDataDownTrigger(JobDetail QingWaterBoiledDataDownJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(QingWaterBoiledDataDownJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(20000);
        return trigger;
    }


    //任务11 DingClallBackJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "DingClallBackJobDetail")
    public MethodInvokingJobDetailFactoryBean DingClallBackJobDetail(DingClallBackJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器11
    @Bean(name = "DingClallBackTrigger")
    public SimpleTriggerFactoryBean DingClallBackTrigger(JobDetail DingClallBackJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(DingClallBackJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(3600000);//每小时检查一次，怕断开
        return trigger;
    }

    //任务12 DingDealCallBackDataJob
    /**
     * 配置定时任务0的任务实例
     * @param  job 任务
     */
    @Bean(name = "DingDealCallBackDataJobDetail")
    public MethodInvokingJobDetailFactoryBean DingDealCallBackDataJobDetail(DingDealCallBackDataJob job) {
        MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
        // 是否并发执行
        jobDetail.setConcurrent(false);
        // 为需要执行的实体类对应的对象
        jobDetail.setTargetObject(job);
        // 需要执行的方法
        jobDetail.setTargetMethod("executeJob");
        return jobDetail;
    }

    // 配置触发器11
    @Bean(name = "DingDealCallBackDataTrigger")
    public SimpleTriggerFactoryBean DingDealCallBackDataTrigger(JobDetail DingDealCallBackDataJobDetail) {
        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(DingDealCallBackDataJobDetail);
        // 设置任务启动延迟
        trigger.setStartDelay(0);
        // 设置定时任务启动时间
        trigger.setStartTime(new Date());
        // 每5秒执行一次
        //trigger.setCronExpression("*/5 * * * * ?"); // 5秒一执行
        trigger.setRepeatInterval(5000);//每5秒检查一次，怕断开
        return trigger;
    }

}
